{% extends "template.html" %}
{% block extrahead %}{{ block.super }}
    <script TYPE="text/javascript"
            SRC="/ui/pkg/pdfmake/pdfmake.min.js"></script>
    <script TYPE="text/javascript"
            SRC="/ui/pkg/pdfmake/vfs_fonts.js"></script>
{% endblock %}
{% block extrastyle %}{{ block.super }}
    {% for s in styles %}
        <link rel="stylesheet" type="text/css" href="{{ s }}" />
    {% endfor %}
{% endblock %}
{% block content %}
    {% if inline_styles %}
    <style>{{ inline_styles|safe }}</style>
    {% endif %}
    {{ data|safe }}
    <script>
        function getPDF(t) {
            var rows = [],
                table = $(t);
            var makeRow = function(tag, child){
              table.find(tag).find("tr").each(function(i, e) {
                var row = [],
                    childs = $(e).find(child);
                childs.each(function(i, e) {
                    var colSpan = $(e).prop('colSpan') || 1,
                        name = $(e).text();
                    row.push({width: 'auto', text: name, colSpan: colSpan, fontSize: 8});
                });
                rows.push(row);
              });
            }
            makeRow("thead", "th");
            makeRow("tbody", "td");
            pdfMake.createPdf({
              pageSize: 'A4',
              content: [
                {
                  table: {
                    headerRows: 1,
                    keepWithHeaderRows: 1,
                    body: rows
                  },
                  layout: 'lightHorizontalLines'
                }
              ]
            }).download();
        }
    </script>
{% endblock %}
